package com.manage.modules.controller;

import java.util.List;
import java.util.Arrays;

import com.manage.modules.dto.TBaseStationEquipSelectDto;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.manage.common.annotation.Log;
import com.manage.common.core.controller.BaseController;
import com.manage.common.core.domain.AjaxResult;
import com.manage.common.enums.BusinessType;
import com.manage.modules.vo.TBaseStationEquipVo;
import com.manage.modules.bo.TBaseStationEquipQueryBo;
import com.manage.modules.bo.TBaseStationEquipAddBo;
import com.manage.modules.bo.TBaseStationEquipEditBo;
import com.manage.modules.service.ITBaseStationEquipService;
import com.manage.common.utils.poi.ExcelUtil;
import com.manage.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 站点设备Controller
 *
 * @author wx
 * @date 2021-08-12
 */
@Api(value = "站点设备控制器", tags = {"站点设备管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/modules/stationEquip")
public class TBaseStationEquipController extends BaseController {

    private final ITBaseStationEquipService iTBaseStationEquipService;

    /**
     * 设备搜索下拉框
     *
     * @return
     */
    @GetMapping("/option")
    public AjaxResult option(TBaseStationEquipSelectDto selectDto) {
        return AjaxResult.success(iTBaseStationEquipService.option(selectDto));
    }

    /**
     * 查询站点设备列表
     */
    @ApiOperation("查询站点设备列表")
    @PreAuthorize("@ss.hasPermi('modules:stationEquip:list')")
    @GetMapping("/list")
    public TableDataInfo<TBaseStationEquipVo> list(TBaseStationEquipQueryBo bo) {
        startPage();
        List<TBaseStationEquipVo> list = iTBaseStationEquipService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出站点设备列表
     */
    @ApiOperation("导出站点设备列表")
    @PreAuthorize("@ss.hasPermi('modules:stationEquip:export')")
    @Log(title = "站点设备", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TBaseStationEquipVo> export(TBaseStationEquipQueryBo bo) {
        List<TBaseStationEquipVo> list = iTBaseStationEquipService.queryList(bo);
        ExcelUtil<TBaseStationEquipVo> util = new ExcelUtil<TBaseStationEquipVo>(TBaseStationEquipVo.class);
        return util.exportExcel(list, "站点设备");
    }

    /**
     * 获取站点设备详细信息
     */
    @ApiOperation("获取站点设备详细信息")
    @PreAuthorize("@ss.hasPermi('modules:stationEquip:query')")
    @GetMapping("/{equipId}")
    public AjaxResult<TBaseStationEquipVo> getInfo(@PathVariable("equipId") Long equipId) {
        return AjaxResult.success(iTBaseStationEquipService.queryById(equipId));
    }

    /**
     * 新增站点设备
     */
    @ApiOperation("新增站点设备")
    @PreAuthorize("@ss.hasPermi('modules:stationEquip:add')")
    @Log(title = "站点设备", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TBaseStationEquipAddBo bo) {
        return toAjax(iTBaseStationEquipService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改站点设备
     */
    @ApiOperation("修改站点设备")
    @PreAuthorize("@ss.hasPermi('modules:stationEquip:edit')")
    @Log(title = "站点设备", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TBaseStationEquipEditBo bo) {
        return toAjax(iTBaseStationEquipService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除站点设备
     */
    @ApiOperation("删除站点设备")
    @PreAuthorize("@ss.hasPermi('modules:stationEquip:remove')")
    @Log(title = "站点设备", businessType = BusinessType.DELETE)
    @DeleteMapping("/{equipIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] equipIds) {
        return toAjax(iTBaseStationEquipService.deleteWithValidByIds(Arrays.asList(equipIds), true) ? 1 : 0);
    }
}
